﻿using System;
using System.Linq;
using System.Collections.Generic; 
using NTTDATA.BEENChina.ResultCertification.Config; 

namespace NTTDATA.BEENChina.ResultCertification.Checker.Name
{
   
    [Serializable]
    [VerfityAttribute(Id = "VerfityN0202", Name = "补足检证2", CategoryType = EnumCategoryType.姓名, Model = true)]
    public class VerfityN0202 : VerfityOneResult
    { 

        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;
            if (result == null)
            {
                return false;
            }

            if (entryCommon.Equals("30"))
            {
                return false;
            }

            foreach (var rowResult in result)
            {
                foreach (string colResult in rowResult)
                {
                    var splitEntryResult = new Split.SplitEntryResult(
                        ChildImageObject.CategorySetting.DataFormat, colResult);

                    string kanaResult = splitEntryResult.GetNameOfKana();
                   // kanaResult = Util.JaStringUtil.ChangeJaInputToHirakana(kanaResult);

                    string kannjiResult = splitEntryResult.GetNameOfKannji();

                    if  (String.IsNullOrEmpty(kanaResult) && string.IsNullOrEmpty(kannjiResult)) 
                     
                    {
                        continue;
                    }

                    bresult = CheckErrorNameResult(kanaResult, kannjiResult);

                    if (bresult) break;
                }
                if (bresult) break;
            }


            if (bresult)
            {
                System.Console.WriteLine("VerfityN0202");
            }

            return bresult;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="kanaResult"></param>
        /// <param name="kannjiResult"></param>
        /// <returns></returns>
        protected bool CheckErrorNameResult(string kanaResult, string kannjiResult)
        {
            //bool bresult = false;

          /*  if (!String.IsNullOrEmpty(kannjiResult))
            {
               // var kannjiSplit = kannjiResult.Split(new string[] { string.Empty }, StringSplitOptions.None);
                var kannjiSplit = Split.SplitNameResult.GetSplitResult(kannjiResult);

                if (kannjiSplit.Count.Equals(2))
                {
                    //汉字第一部分是非汉字  第二部分非汉字情况下
                    if (!IsKannji(kannjiSplit[0]) && !IsKannji(kannjiSplit[1]))
                    {
                        if (!String.IsNullOrEmpty(kanaResult))
                        {
                             //假名部分如果是空白
                            if (string.IsNullOrEmpty( kanaResult ))
                            {
                                bresult = true;
                            }
                            
                        }
                    }
                }
            }*/
   
            //结果里的问号忽略
            kannjiResult = kannjiResult.Replace("?", string.Empty);

            if (!String.IsNullOrEmpty(kannjiResult))
            {
                bool containsKannji = kannjiResult.ToCharArray().Any(Util.StrHelper.IsKannji);

                if (!containsKannji)
                {
                    if (String.IsNullOrEmpty(kanaResult))
                        return true;
                }
            }
            return false;
        }

        
        
    }
}
